Set indexing for first-level and second-level set-associative cache

ABSTRACT

An apparatus comprises first-level and second-level set-associative caches each comprising the same number of sets of cache entries. Indexing circuitry generates, based on a lookup address, a set index identifying which set of the first-level set-associative cache or the second-level set-associative cache is a selected set of cache entries to be looked up for information associated with the lookup address. The indexing circuitry generates the set index using an indexing scheme which maps the lookup address to the same set index for both the first-level set-associative cache and the second-level set-associative cache. This can make migration of cached information between the cache levels more efficient, which can be particularly useful for caches with high access frequency, such as branch target buffers for a branch predictor.

BACKGROUND Technical Field

The present technique relates to the field of caches.

Technical Background

A data processing system may have one or more caches for cachinginformation associated with a subset of addresses. The caches can belooked up based on a lookup address to identify whether any of thecaches is storing valid information associated with the lookup address.

SUMMARY

At least some examples provide an apparatus comprising:

a first-level set-associative cache comprising a plurality of sets ofcache entries;

a second-level set-associative cache comprising a plurality of sets ofcache entries, where a number of sets in the first-level set-associativecache is the same as a number of sets in the second-levelset-associative cache; and

indexing circuitry to generate, based on a lookup address, a set indexidentifying which set of the first-level set-associative cache or thesecond-level set-associative cache is a selected set of cache entries tobe looked up for information associated with the lookup address,

where the indexing circuitry is configured to generate the set indexusing an indexing scheme which maps the lookup address to the same setindex for both the first-level set-associative cache and thesecond-level set-associative cache.

At least some examples provide an apparatus comprising:

first-level means for caching information in a plurality of sets ofcache entries accessed according to a set-associative cache accesspolicy;

second-level means for caching information in a plurality of sets ofcache entries accessed according to a set-associative cache accesspolicy, where a number of sets in the first-level means for caching isthe same as a number of sets in the second-level means for caching; and

means for generating, based on a lookup address, a set index identifyingwhich set of the first-level means for caching or the second-level meansfor caching is a selected set of cache entries to be looked up forinformation associated with the lookup address;

where the means for generating is configured to generate the set indexusing an indexing scheme which maps the lookup address to the same setindex for both the first-level means for caching and the second-levelmeans for caching.

At least some examples provide a method comprising:

caching information in a first-level set-associative cache comprising aplurality of sets of cache entries;

caching information in a second-level set-associative cache comprising aplurality of sets of cache entries, where a number of sets in thefirst-level set-associative cache is the same as a number of sets in thesecond-level set-associative cache; and

generating, based on a lookup address, a set index identifying which setof the first-level set-associative cache or the second-levelset-associative cache is a selected set of cache entries to be looked upfor information associated with the lookup address, where the set indexis generated using an indexing scheme which maps the lookup address tothe same set index for both the first-level set-associative cache andthe second-level set-associative cache.

Further aspects, features and advantages of the present technique willbe apparent from the following description of examples, which is to beread in conjunction with the accompanying drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 schematically illustrates an example of a data processing systemhaving a number of types of cache;

FIG. 2 shows an example of a branch predictor having a number of branchprediction caches, including a level one branch target buffer (BTB) anda level two BTB;

FIG. 3 illustrates an example of a set-associative cache;

FIG. 4 shows, for comparison, an approach where the second-levelset-associative cache has a different number of sets and a differentindexing scheme to a first-level set-associative cache;

FIG. 5 shows an approach where the first and second levels of cacheshare a same indexing scheme and have the same number of sets;

FIGS. 6 and 7 contrast dual-ported cache RAM (random access memory) andsingle-ported cache RAM;

FIG. 8 is a flow diagram illustrating a method of use for a multi-levelcache hierarchy; and

FIG. 9 shows in more detail a method for controlling lookups of thefirst and second levels of cache.

DESCRIPTION OF EXAMPLES

A processing system may have multiple levels of cache in a cachehierarchy. it may be desirable to provide increased cache capacity byincreasing a number of cache entries in a given cache, but in general,the larger the cache, the slower the cache will be to access because theincreased size means that signal paths for accessing the cache becomelonger and increase the latency of accessing the cache. In comparison toa single level of cache (which has equivalent cache capacity to thetotal capacity of the multiple levels of cache in the hierarchy), amulti-level cache hierarchy can provide a better balance betweencapacity and performance, as access to a first-level cache holding asmaller amount of data can be faster than would be possible for a singlelarge cache; but when there is a miss in the first-level cache then thesecond-level cache provides additional storage capacity.

The first and second levels of cache may each be implemented as aset-associative cache, where the cache entries are logically dividedinto a number of sets. When the data in one of the caches needs to beaccessed, indexing circuitry generates, based on a lookup address(representing the address associated with information to be written toor read from the cache), a set index identifying which set of entries ofthe first-level cache or second-level cache is a selected set of cacheentries to be looked up for information associated with the lookupaddress. Each set of entries may comprise a certain number of cacheentries, where the number of cache entries in one set is referred to asthe associativity of the cache. The set-associative cache could be adirect-mapped cache (which is a special case of a set-associative cachefor which the associativity is one) or could be a set-associative cachewith an associativity of two or more. The set-associative scheme meansthat information associated with a particular address may be allocatedto any of the cache entries in the selected set of cache entries whichcorresponds to the set index derived from the given address, but is notallowed to be allocated to a different set of cache entries associatedwith a different value of the set index.

When a multi-level cache hierarchy is provided, in typical schemes it isusual for the second-level set-associative cache to use a differentindexing scheme and a different number of sets compared to thefirst-level set-associative cache in the hierarchy. This can be usefulto allow the second-level cache to provide a greater capacity forexample, without paying the circuit area and power penalty of increasingthe associativity of the second-level set-associative cache excessivelywhich would incur extra circuit overhead in implementing additionalcomparators for comparing tags for determining whether each entry in theindexed set corresponds to the lookup address. Hence, it is conventionalfor the first and second levels of set-associative cache to usedifferent numbers of sets and different set indexing schemes so that thelookup address would be mapped to different set indices for the firstand second levels of cache respectively.

However, the inventors recognised that this approach can cause someperformance issues in some scenarios where cache entries are migratedbetween levels of cache. This can be a particular problem formulti-level cache hierarchies which need to support fast performance,such as caches in branch predictors for example.

In the examples discussed below, the second-level set-associative cacheis provided with the same number of sets as the first-levelset-associative cache. This does not necessarily mean that the number ofcache entries in the second-level set-associative cache is the same asthe number of cache entries in the first-level set-associative cache, asthe first and second levels of cache could still have differentassociativity (different numbers of entries per set). However, byaligning the number of sets in the first and second levels of cache andusing a common indexing scheme which maps the lookup address to the sameset index for both the first and second levels of set-associative cache,this can speed up performance especially when migrating entries betweenthe first and second levels of cache. The indexing scheme used for thefirst-level and second-level set-associative caches may be incapable(for any given address selected as the lookup address) of mapping thelookup address to a different set index for the first-levelset-associative cache compared to the set index for the second-levelset-associative cache. In other words, the set indices for thefirst-level and second-level caches are constrained to be the same forany given lookup address.

While the examples below are discussed in the context of the first-levelcache and a second-level cache, the overall cache hierarchy of which thefirst-level and second-level caches form a part may have more than twolevels in some examples, and in this case the first-level cache andsecond-level cache could be any two levels of cache within the hierarchy(e.g. the “first-level” and “second-level” caches described below couldbe the level-1 and level-2 caches of a 3-level cache hierarchy, or couldbe the level-2 and level-3 caches of a 3-level cache hierarchy). Hence,the technique is not limited to only having two levels of cache, and the“first-level” and “second-level” caches do not need to correspond tolevel-1 and level-2 respectively—there could be at least one furtherlevel cache which is accessed in the cache hierarchy prior to the“first-level” cache.

Cache access circuitry may be provided to perform a first cache lookupto determine whether any of the selected set of cache entries in thefirst-level set-associative cache caches the information associated withthe lookup address, and a second cache lookup to determine whether anyof the selected set of cache entries in the second-level set-associativecache caches the information associated with the lookup address. Thesecond cache lookup may not be necessary for all accesses to the cachehierarchy, for example if there is a hit in the first cache lookup thenthe second cache lookup could be suppressed. In some examples, thesecond-level cache may be looked up only in the event of a cache miss inthe first-level cache. In other examples, the second-level cache couldbe looked up (in some scenarios at least) even if there is a cache hitin the first-level cache. For example, in some implementations, aspeculative access to the second-level cache could be initiated prior todetermining whether the lookup of the first-level cache identifies a hitor miss, to reduce the overall latency of accessing the second-levelcache). Other designs may choose not to lookup the second-level cachespeculatively to save power, but may still support lookups of thesecond-level cache in some scenarios when there is a cache hit in thefirst-level cache. For example, some forms of multi-level cache maysupport storing multiple entries corresponding to the same lookupaddress, with one entry for that lookup address stored in thefirst-level cache and another entry for the same lookup address storedin the second-level cache. For example, in a branch target bufferstructure for caching information on target addresses of branchinstructions, for which the lookup address is an instruction blockaddress identifying a block of multiple instructions, it is possiblethat an instruction block could comprise multiple branches in the sameblock and so it may be desired in some designs to allow both thefirst-level and second-level caches to store entries corresponding tothe same instruction block address, to allow predictions of targetaddresses for multiple branches in the same block. Therefore, sometimesit may be desirable to perform the second cache lookup even if there isa hit in the first cache lookup.

When the second cache lookup identifies a cache hit (where a hit entryof the selected set of cache entries in the second-level cache cachesthe information associated with the lookup address), and there is noinvalid entry in the selected set of cache entries of the first-levelcache which can accommodate the information from the hit entry of thesecond-level cache, the cache access circuitry may swap contents of thehit entry of the second-level cache and a victim entry of the selectedset of cache entries in the first-level cache. As the lookup addresscorresponds to the same set index for both the first and second levelsof cache, this means that promotions of entries from the second level tothe first level can be implemented simply by swapping contents ofrespective entries in the first and second levels of cache, so only twoentries in total would need to be updated, one in the first-level cacheand one in the second-level cache. In contrast, if different numbers ofsets and different set indexing schemes were used for the first andsecond levels of cache, then when promoting data from the second levelto the first level could sometimes require eviction of data from thefirst-level cache associated with an address which maps to a differentset in the second level cache other than the set including the hitentry, so that three different cache entries would need to be updated toimplement the migration, one in the first level of cache and two in thesecond level of cache. The alignment of the set indexing schemes for thetwo levels of caches therefore helps to improve performance byeliminating the need for this third entry update.

Hence, when the second cache lookup identifies the cache hit and anentry of the first-level cache needs to be evicted as there is noinvalid entry available for accommodating the data from the hit entry,the cache entry of the second-level set-associative cache that isupdated with contents of the victim entry of the first-levelset-associative cache may be the hit entry of the second-level cacheregardless of which address is associated with information cached in thevictim entry of the first-level set-associative cache. This contrastswith the case if different set indexing schemes were used for the firstand second level caches, in which case the entry of the second levelcache that would be updated with evicted contents form the first levelcache would be selected depending on tag information indicating whichaddress is associated with a victim entry of the first-level cache formwhich the information was evicted.

When swapping the contents of the hit entry of the second-level cacheand the victim entry of the first-level cache, the cache accesscircuitry may perform an atomic update operation on the hit entry andthe victim entry. The atomic update operation may be an operation toupdate multiple entries in a way that is perceived as indivisible by anyrequester which triggers a lookup of the first-level or second-levelcaches. That is, subsequent requests to lookup the caches may see theeffects of the atomic updates on both the hit entry and the victimentry, or see the effects of neither of the updates made to the hitentry and the victim entry, but are not allowed to trigger a lookupresponse which would reflect that only one of the updates of the hitentry and the victim entry has taken place already while the other ofthese entries has not yet been updated. By updating the hit entry andthe victim entry through an atomic update operation, this helps topreserve performance by reducing the risk of information for aparticular address previously held in one of the first-level andsecond-level caches temporarily being indicated as not being cached ineither of the first-level and second-level caches, which could be a riskif one of the hit entry and victim entry was updated first and then theother was updated subsequently, rather than updating them atomically.There may be a number of ways of enforcing an atomic update. Oneapproach could be to prevent lookups to the cache being made in theperiod between updating one of the entries and updating the other.However, for improving performance, some systems may allow lookups tocontinue but may enforce the atomic update by providing a mechanismwhere a single write request may cause entries in both caches to beupdated simultaneously. For example, due to the alignment of the setindexing schemes it may be possible to read out an entire set of entriesidentified by the same set index in both caches, perform the requiredupdates while the read out sets of entries from both levels of cache aretemporarily stored elsewhere and then write the updated values for therespective sets of entries back to the first and second levels of cachein a single operation.

When both the first and second cache lookups identify a cache miss wherenone of the selected set of cache entries in both the first/second-levelcaches holds the information associated with the lookup address, newinformation associated with the lookup address may be allocated into thecache structure. A first victim entry may be selected from the selectedset of cache entries in the first-level cache and a second victim entrymay be selected from the selected set of cache entries of thesecond-level cache. Contents of the first victim entry may be writtenfrom the first-level cache to the second victim entry in the selectedset of the second-level cache, and the first victim entry in thefirst-level cache may be allocated for storing the informationassociated with lookup address.

Again, this process for evicting information from the first victim entryto the second victim entry may be made faster by the fact that the firstand second levels of cache share the same indexing scheme. Since the setindex for identifying the selected set of cache entries corresponding tothe lookup address is the same in both the first-level and second-levelcaches regardless of which address corresponds to the first victimentry, this means it is not necessary to check contents of the firstvictim entry to determine the set of the second-level cache to which thecontents of the first victim entry should be evicted. In contrast, withstandard approaches where the second-level cache has a different setindexing scheme from the first-level, it would be needed to check a tagportion of the first victim entry to determine which address isassociated with that entry so that that address can then be mapped tothe set index according to the second set indexing scheme used for thesecond-level cache. This is not necessary in the technique discussedbelow because of the alignment of indexing schemes.

Hence, when selecting the second victim entry, the selection of thesecond victim entry may be independent of the contents of the firstvictim entry, which can be useful for performance because it may allowsome processes for selecting the second victim entry to be initiatedearlier than would be possible if the contents of the first victim entryhad to be read first.

For example, selection of the second victim entry may be based onreplacement policy information associated with the selected set of cacheentries of the second-level set-associative cache. The replacementpolicy information may be read before a read of the first victim entryis complete, which helps to improve performance. Also, the reading ofthe replacement policy information may be performed in parallel with atleast one of: the first cache lookup, the second cache lookup, andreading of the first victim entry to obtain the contents to be writtento the second victim entry. This might not be possible inimplementations which use different indexing schemes for the first andsecond levels of cache.

When updating the first and second victim entries to allocate the firstvictim entry for storing the information associated with the lookupaddress and writing the contents of the first victim entry to the secondvictim entry, the cache access circuitry may update the first and secondvictim entries by performing an atomic update operation, which asmentioned above ensures that subsequent lookups see the effects of bothupdates and cannot only see a partial update of one of the entries whilethe other is not updated. This helps to improve performance by avoidingloss of performance caused by non-atomic updates which could risk alookup temporarily seeing that a given address is not cached at all inthe hierarchy when actually this is because the corresponding entry wasbeing transferred to a different cache level. Again, the atomic updateoperation could be implemented in different ways, e.g. by providing ahardware mechanism for a unified read/write/update operation to updateinformation in the selected set of entries in both first-level andsecond-level caches simultaneously.

Access latency may be greater for accesses to the second-level cachethan for accesses to the first-level cache. Hence, in response to acache access request to request information associated with the lookupaddress, when the information associated with the lookup address isobtained from the first-level set-associative cache, the information isaccessible in fewer cycles than when the information associated with thelookup address is obtained from the second-level set-associative cache.

The alignment of set indexing schemes can be particularly useful wherethe second-level set-associative cache is an exclusive cache. For aninclusive cache, each entry cached in the first-level cache also has acorresponding entry in the second-level cache. In contrast, for anexclusive cache the second-level cache need not contain any entryassociated with an address for which the first-level cache holds a validentry. While an exclusive policy may help to increase the number ofdistinct addresses which can be cached within the cache hierarchy, usingan exclusive policy may increase the overhead in handling evictions fromthe first-level cache, as it may require second-level cache entries tobe updated/evicted/allocated when an entry is evicted from thefirst-level cache (which would not be necessary in an inclusive schemeas there would already be a second-level cache entry corresponding tothe information evicted from the first-level cache). The alignment ofthe set indexing schemes between the first and second levels of cachecan therefore be particularly beneficial for cache hierarchies where thesecond-level cache is an exclusive cache, as the alignment of setindexing schemes helps to reduce the performance cost of managing suchevictions since the set to allocate the data into in the second-levelcache can be known before the victim entry has been read from thefirst-level cache.

The number of ways (cache entries) per set can be the same in thefirst-level set-associative cache and the second-level set-associativecache. Alternatively, the first and second levels of cache may havedifferent numbers of ways per set (while still having the same number ofsets). In some implementations, the second-level cache could have asmaller number of ways per set than the first-level cache (it is notessential for the capacity of the second-level cache to be greater thanthe first-level cache, when an exclusive cache is used for thesecond-level cache). However, in some implementations, the second-levelset-associative cache may have a greater number of ways per set than thefirst-level set-associative cache. This means that the capacity of thesecond-level cache may be greater than the capacity of the first-levelcache.

One might consider it to be counter-intuitive to use the same number ofsets in the second-level cache as in the first-level cache, because fora given size of second-level cache designed to provide a certainrequired number of cache entries, if the number of sets has to bereduced to match the number of sets in a smaller first-level cache, thenthis would imply that the number of ways (cache entries) per set wouldneed to increase (the second-level cache would have greaterassociativity than the first-level cache in that case). Normally, whenimplementing a cache with a certain number of entries, a designer mayfavour increasing the number of sets compared to increasing the numberof ways, because each additional way incurs an incremental circuit areaand power cost of providing additional comparison logic for comparing anaddress tag stored in that way with a corresponding tag portion of thelookup address. In contrast, increasing the number of sets does notincur as great an incremental cost as it can be implemented by changinga hash function used by the indexing circuitry to derive the set indexfrom the lookup address and increasing the number of bits allocated forthe set index, which would typically incur a lower additional cost peradditional set than would be incurred per additional cache way. This iswhy many conventional approaches would not align the number of sets inthe first and second levels of cache. However, counter-intuitively, theinventors recognise that for the reasons discussed above, aligning thenumber of sets in the first and second cache levels can help to improveperformance associated with migrating entries between levels of cache,which may be preferred for some implementations even at the expense ofadditional circuit area/power cost of additional cache ways.

This technique can be particularly useful in cases where the first-levelset-associative cache and the second-level set-associative cache eachcomprise single-ported random access memory (RAM). Unlike dual-portedcache RAM which may have two write/read ports and so may be capable oftwo simultaneous read or write operations per cycle, a single-portedcache RAM may only be capable of a single read or write operation percycle, because there may only be access ports for supplying a singleaddress and access request per cycle (note that the address provided onthat access port would be an address defined according to the hardwareRAM structure of the cache memory hardware, which may be in a differentaddress space from the address space defined for the lookup addressbeing looked up in the cache). While the techniques discussed abovecould be useful even for dual-ported cache RAMs, the techniques can beparticularly useful in cases where the cache comprises single-portedRAM, as the single-ported RAM imposes restrictions on the rate at whichentries can be read/updated in the caches, so eliminating the thirdentry update on promoting entries from the second-level cache to thefirst-level cache, or reducing latency by enabling victim entries to beidentified earlier as described in the earlier examples, can beparticularly beneficial for single-ported RAM embodiments. In someimplementations, the first-level cache and second-level cache may eachcomprise a separate module of single-ported RAM, so that there is oneaccess port for the first-level cache and one access port for thesecond-level cache. Other examples may provide a single access portshared between both cache levels (i.e. the first-level and second-levelcache may correspond to different portions of a single cache RAM module,but where the locations associated with the first-level cache may beaccessible with shorter latency than the locations associated with thesecond-level cache).

The techniques discussed above can be used for a wide variety of typesof cache. For example, the cache could comprise one of a data cache, aninstruction cache or an address translation cache such as a translationlookaside buffer.

Also, the technique could be applied to first-level and second-levelcaches which act as predictive storage structures to cache predictioninformation used to determine predicted behaviour associated with thelookup address. For example, the predicted behaviour could be used tocontrol speculative operations by a processor. A recovery mechanism maybe provided to trigger a recovery action when a mispredictions isidentified. The prediction information stored in the first-level andsecond-level caches could be updated based on actual behaviour detectedfrom executing instructions. For example, the first-level andsecond-level set-associative caches may provide branch predictioninformation used by branch prediction circuitry to determine predictedbranch instruction behaviour. The techniques discussed above could alsobe used for multi-level cache hierarchies used as other types ofprediction storage structure, not related to branch prediction, such asan address prediction structure for predicting patterns of addresses ofinstructions to be executed or data accesses to be made to memory, whichcould be used to initiate early requests to obtain data or instructionsfrom memory or a cache. It will be appreciated that other aspects ofprocessing apparatus behaviour could also be predicted using apredictive storage structure. For any of such types of cache, whenimplemented using a multi-level cache hierarchy with first and secondlevels of cache, the first and second levels may be provided with thesame number of sets and use a common indexing scheme as discussed above.

However, the technique is particularly useful for branch predictioncircuitry, because often the performance requirements for branchprediction circuitry may be greater than for data caches or other typesof cache where a slower performance may be tolerated. For branchpredictors in particular, the branch predictor is a very busy componentof a data processing system because it may be looked up on every cycleto identify possible branch prediction information for determining thenext fetch address to be looked up in the following cycle. In contrastother types of cache may be accessed less frequently. Hence, thetechniques discussed above for aligning the set indexing schemes forfirst-level and second-level set-associative caches can be particularlybeneficial for branch prediction caches.

In particular, the branch prediction circuitry may have a branch targetbuffer (BTB) which caches branch target buffer information whichindicates properties of taken branch instructions predicted to occurwithin a block of instructions associated with a given address. The BTBmay be implemented as a multi-level cache hierarchy, and so thefirst-level and second-level caches mentioned earlier may be first-leveland second-level BTBs. Branch prediction circuitry may determine apredicted target address for a first taken branch instruction predictedto occur within a block of one or more instructions associated withlookup address based on branch target buffer information cached in acache entry of the first-level or second-level set-associative cacheassociated with lookup address. In such a branch target buffer,performance demands are extremely high compared to other types of cachesbecause the prediction information provided by the branch target bufferis used to form a prediction of a branch target address which may thenbe used as the lookup address for a subsequent cycle, and so delays inlooking up the caches may cause bubbles in the pipeline. Ifsingle-ported RAM is used to implement the level one and level two BTBs,then this may create a challenge in handling movement of data betweenthe levels of cache while still meeting performance demands. By using acommon indexing scheme for both levels of cache and an identical numberof sets in both levels of cache for the BTB, this can greatly help toreduce the latency of entry migrations and hence improve performance.

FIG. 1 schematically illustrates an example of a data processingapparatus 2. The data processing apparatus has a processing pipeline 4which includes a number of pipeline stages. In this example, thepipeline stages include a fetch stage 6 for fetching instructions froman instruction cache 8; a decode stage 10 for decoding the fetch programinstructions to generate micro-operations to be processed by remainingstages of the pipeline; an issue stage 12 for checking whether operandsrequired for the micro-operations are available in a register file 14and issuing micro-operations for execution once the required operandsfor a given micro-operation are available; an execute stage 16 forexecuting data processing operations corresponding to themicro-operations, by processing operands read from the register file 14to generate result values; and a writeback stage 18 for writing theresults of the processing back to the register file 14. It will beappreciated that this is merely one example of possible pipelinearchitecture, and other systems may have additional stages or adifferent configuration of stages. For example in an out-of-orderprocessor a register renaming stage could be included for mappingarchitectural registers specified by program instructions ormicro-operations to physical register specifiers identifying physicalregisters in the register file 14.

The execute stage 16 includes a number of processing units, forexecuting different classes of processing operation. For example theexecution units may include a scalar arithmetic/logic unit (ALU) 20 forperforming arithmetic or logical operations on scalar operands read fromthe registers 14; a floating point unit 22 for performing operations onfloating-point values, a branch unit 24 for evaluating the outcome ofbranch operations and adjusting the program counter which represents thecurrent point of execution accordingly; and a load/store unit 28 forperforming load/store operations to access data in a memory system 8,30, 32, 34. A memory management unit (MMU) 36 controls addresstranslations between virtual addresses specified by load/store requestsfrom the load/store unit 28 and physical addresses identifying locationsin the memory system, based on address mappings defined in a page tablestructure stored in the memory system. The page table structure may alsodefine memory attributes which may specify access permissions foraccessing the corresponding pages of the address space, e.g. specifyingwhether regions of the address space are read only or readable/writable,specifying which privilege levels are allowed to access the region,and/or specifying other properties which govern how the correspondingregion of the address space can be accessed. Entries from the page tablestructure may be cached in a translation lookaside buffer (TLB) 38 whichis a cache maintained by the MMU 36 for caching page table entries orother information for speeding up access to page table entries from thepage table structure shown in memory.

In this example, the memory system include a level one data cache 30,the level one instruction cache 8, a shared level two cache 32 and mainsystem memory 34. It will be appreciated that this is just one exampleof a possible memory hierarchy and other arrangements of caches can beprovided. The specific types of processing unit 20 to 28 shown in theexecute stage 16 are just one example, and other implementations mayhave a different set of processing units or could include multipleinstances of the same type of processing unit so that multiplemicro-operations of the same type can be handled in parallel. It will beappreciated that FIG. 1 is merely a simplified representation of somecomponents of a possible processor pipeline architecture, and theprocessor may include many other elements not illustrated forconciseness.

The apparatus 2 also has a branch predictor 40 which may include one ormore branch prediction caches 42 for caching prediction information usedto form predictions of branch behaviour of branch instructions to beexecuted by the branch unit 24. The predictions provided by the branchpredictor 40 may be used by the fetch stage 6 to determine the sequenceof addresses from which instructions are to be fetched from theinstruction cache 8 or memory system. The branch prediction caches mayinclude a number of different forms of cache structure, including abranch target buffer (BTB) which may cache entries specifyingpredictions of whether certain blocks of addresses are predicted toinclude any branches, and if so, the instruction address offsets(relative to the start address of the block) and predicted targetaddresses of those branches. Also the branch prediction caches 42 couldinclude branch direction prediction caches which cache information forpredicting, if a given block of instruction addresses is predicted toinclude at least one branch, whether the at least one branch ispredicted to be taken or not taken.

Hence, the data processing system may include a number of cachestructures, including for example the data cache 30, instruction cache8, level 2 cache 32, TLB 38 and/or branch prediction caches 42. It willbe appreciated that other types of cache structure could also beprovided. For example, other types of prediction caches could include adata prefetcher cache which caches information for predicting dataaddresses for future load/store instructions to be processed by theload/store unit 28, or an instruction prefetcher cache which cachesinformation for predicting which instructions may need to be fetchedinto the instruction cache 8 prior to those addresses actually beingrequested by the fetch stage 6.

FIG. 2 shows in more detail components of the branch predictor 40 whichcomprises a branch direction predictor (BDP) 60 and branch target buffer(BTB) 64. The BDP 60 is for predicting whether the branch direction istaken or not taken for a branch within a block of instructionsrepresented by a lookup address 80. The BDP 60 could use any branchdirection prediction technique, such as bimodal prediction, TAGE,perceptron, etc. The BDP 60 has a number of branch direction predictioncaches 62 for caching branch prediction state used to determine thepredicted branch direction 88 for a first taken branch within the blockof addresses represented by the lookup address 80.

The branch target buffer 64 provides a prediction of various branchproperties associated with one or more branches within a block ofinstructions associated with the lookup address 80. The BTB 64 hasindexing circuitry 66 for generating a set index 84 for indexing into alevel 1 (L1) BTB 68 and a level 2 (L2) BTB 70. The L1 and L2 BTBs 68, 70are examples of the first-level and second-level set-associative cachesdescribed earlier. Cache access circuitry 72 is provided for controllingaccess to the L1 BTB 68 and L2 BTB 70 based on the set index 84. Basedon lookups of the L1 BTB 68 and L2 BTB 70, the cache access circuitry 72determines whether there is any branch information held in the BTBs 68,70 for the lookup address, the branch information indicating variousbranch properties to be predicted, including at least the predictedtarget address 86 of a first taken branch expected to be present withinthe block of instructions associated with the lookup address. Based onthe predicted branch direction 88 and predicted target address 86provided by the BDP 60 and the BTB 64 respectively, branch predictioncircuitry 74 determines a predicted behaviour 90 associated with thelookup address 80, where for the branch predictor 40 the predictedbehaviour 90 is a fetch address to be used in a subsequent cycle N+1after the cycle N in which the fetch address used as the lookup address80 is provided. That is, the predicted address output as the fetchaddress for cycle N+1 may become the lookup address in the followingcycle. Instructions may be fetched from a sequence of fetch addressesdetermined based on the predictions made by the branch predictor.

Information in the BDP caches 62 and L1 and L2 BTBs 68, 70 is updatedbased on actual results of executed branches determined by the branchunit 24 in the execute stage 16.

The L1 BTB 68 and L2 BTB 70 may each be implemented as set-associativecaches. As shown in FIG. 3, a set-associative cache has a number ofentries 52 which are logically partitioned into a number of sets 50.Each set comprises a certain number of entries (or cache ways), and thenumber of ways per set is referred to as the associativity of the cache.For example, FIG. 3 shows an example of a 4-way set-associative cache,which means that each set 50 comprises 4 entries 52.

When looking up the cache to determine whether the cache holds validdata for a given lookup address 80, the indexing circuitry 66 for thecache maps the cache to a set index 84 which identifies which set 50 isto be looked up, and then tag portions 56 of each entry 52 in theselected set identified by the set index are read out and compared witha tag portion 85 derived from the lookup address 80 itself. If any ofthe entries 52 in the selected set 50 have a tag 56 which matches thetag 85 derived from the lookup address 80, then a cache hit is detectedand data 58 in the hit entry having the matching tag 56 is returned ascached information corresponding to the lookup address 80. If all of theentries in the selected set 50 identified by the set index have tags 56which do not match the tag 85 associated with a lookup address 80 then acache miss is detected, and so this cache is not able to provide validdata associated with the lookup address.

Hence, when the BTB 64 needs to be looked up based on the lookup address80 the indexing circuitry 66 uses a hash function to map the lookupaddress 80 to the set index 84. In some examples, as shown in FIG. 2 thehash function for generating the set index 84 may also depend on historyinformation 82 which indicates properties associated with a certainnumber of previous branches, e.g. indicating a sequence oftaken/not-taken outcomes for a certain number of most recently executedor predicted branches, or portions of bits from target addresses of anumber of recent branches. The history information 82 can be used todistinguish different paths by which a given branch may be reached in agiven program, which can help to provide more accurate predictions ofdifferent branch target addresses for different paths taken to reach thebranch.

The L2 BTB 70 is slower to access than the L1 BTB 68. Typically the L2BTB may be looked up when there is a miss in the L1 BTB (although someimplementations may support looking up the L2 BTB even if there is a hitin the L1 BTB, for example if the L2 BTB is capable of storinginformation on additional branches within the same block of instructionsas the block whose lookup address is being looked up in the L1 BTB 68,so that it is possible that the lookup address could hit in bothstructures).

In the techniques described below the set index 84 used for indexinginto the L1 and L2 BTBs 68, 70 is the same, and the same hash functionis used by the indexing circuitry 66 to generate the set index 84 forboth L1 and L2 BTB 68, 70. This can help to support fast read/writes tothe respective BTBs in cases where entries need to be migrated betweenthe BTBs, which might otherwise not be straightforward for instanceswhere the L1 and L2 BTB 68, 70 are implemented using single-ported RAM.

FIG. 4 is a diagram for explaining issues which arise in implementationswhich use a different number of sets in the L2 BTB 70 compared to the L1BTB 68, and which use a different set indexing scheme. In such animplementation it is possible that a given address may map to adifferent set in the L2 BTB 70 compared to the L1 BTB 68. This can causesome issues when needing to promote or demote entries to migrate thembetween the BTBs 68, 70 in cases where a first cache lookup into the L1BTB 68 identifies a cache miss.

As shown in FIG. 4, when the BTB 64 receives a request specifying thelookup address 80, the BTB can check both L1 L2 BTBs 68, 70 to determinewhether there is a hit entry corresponding to the lookup address. Ifthere is a hit entry in the L1 BTB 68, no update is needed.

If both L1 and L2 lookups miss for the lookup address (case 1illustrated in FIG. 4), and it is determined that branch information fora branch BrA associated with that lookup address needs to be allocated,and there is no spare invalid entry available in the set of the L1 BTB68 corresponding to the lookup address, a victim entry is selected inthe corresponding set of the L1 BTB, and information for BrA can beallocated to that victim entry (a first access). However, theinformation for the branch BrX previously represented by the victim L1BTB entry will then be migrated to a second victim entry in the L2 BTB,and the information for the branch BrY represented by the second victimentry may be discarded (the update of the second victim entry to changethe information for branch BrY to the information for branch BrX is asecond access), As the address of branch BrX may correspond to adifferent set in the to the address

Alternatively, if the L1 lookup misses, but the L2 lookup hits in anentry corresponding to branch BrA (case 2 illustrated in FIG. 4), theentry for branch BrA is migrated to the L1 BTB where (if there are nospare invalid entries in the set corresponding to the lookup address) afirst victim entry is selected in L1 BTB to be evicted to L2 BTB 70 andreallocated for representing BrA instead of BO which was previouslyrepresented by the first victim entry. The victimized entry from L1 BTBthen seeks space in the L2 BTB (which may need a further access to asecond victim entry in the L2 BTB 70 since BrA and Br1 may be mapped todifferent sets in the L2 BTB). The information for the branch Br2represented by the second victim entry is discarded. Hence, if differentset indexing schemes are used, in case 2 it may be needed to update 3different entries in the BIB hierarchy: invalidating the L2 BTB entryfor BrA being promoted to the L1 BTB; updating the first victim entryfor Br1 in the L1 BTB to reallocate it to branch BrA, and updating thesecond victim entry for Br2 in the L2 BTB to reallocate it to branchBr1.

Also, the use of different set indexing schemes for the two levels ofcache 68, 70 means that when information for a given branch BrX, Br1needs to be demoted from the L1 BTB 68 to the L2 BTB 70, the cacheaccess circuitry 72 cannot start to determine which entry of the L2 BTB(BrY or Br2) should be updated with the information demoted from the L1BTB 68 until after the tag information 56 associated with the victimentry in the L1 BTB has been read, because it is possible that the entryto be updated using the evicted information could be in a different setto the set accessed for the initial L2 BTB lookup.

FIG. 5 shows a different approach where the L1 BTB 68 and L2 BTB 70 areprovided with the same number of sets 50 and the indexing circuitry 66maps the lookup address 80 to the same set index 84 for both the L1 andL2 BTBs 68, 70. Therefore, the indexing circuitry 66 uses the sameindexing scheme for both levels and is incapable of mapping a givenlookup address 80 to different set indices in the respective L1 and L2BTBs 68, 70. In this example, the L2 BTB 70 has a greater associativitythan the L1 BTB 68, for example in this case the L1 BTB 68 comprises 4ways while the L2 BTB comprises 12 ways. However, this is not essentialand other numbers of ways may be provided in both the L1 and L2 BTB 68,70, The L2 BTB 70 acts as an exclusive cache, which means that the L2BTB 70 does not guarantee that all addresses having valid entries cachedin the L1 BTB 68 will also have a corresponding entry in the L2 BTB 70.

Logically, as shown in FIG. 5 the two-level BTB 68, 70 as a whole may beconsidered to be a monolithic large set-associative cache structure witha certain number of ways per set (16 ways in total in this example), butfrom a physical hardware point of view the BTB is split into two parts,a fast zone representing the L1 BIB 68 and a slow zone representing theL2 BTB 70, Entries 52 in the fast zone 68 can be accessed in fewercycles than entries in the slow zone 70. For example this may be becauselonger wires may be needed to reach the entries 52 in the slow zone 70(e.g. because the slow zone entries may be further away from the cacheaccess circuitry 72 on an integrated circuit compared to the fast zoneentries 68).

With this approach, faster operations are possible for migrating entriesbetween the levels, due to the common set indexing scheme. In case 1explained with respect to FIG. 4, where the lookup address for a certainbranch BrA misses in both the L1 and L2 BTB 68, 70, then a first victimentry 100 for branch BrX in the fast zone 68 may be victimised andpushed out to the slow zone where it replaces a second victim entry 102within the L2 BTB 70, The contents of the second victim entry 102 may bediscarded, Due to the common set indexing scheme used for both levels ofcache 68, 70, operations for selecting the second victim entry 102 canbegin before contents of any entries of the selected set correspondingto the lookup address 80 in the first level BTB 68 have been read,because the selected set for the second level BTB 70 will already beknown at the point when the set index 84 is generated for thefirst-level BTB lookup, and so it is not necessary for such victimselection operations for selecting the second victim entry 102 to bemade sequentially after reading information from the first victim entry100 such as the tag portion 56 used to identify which address is beingevicted. This is because in the case of FIG. 5, unlike in FIG. 4, theset used to provide the second victim entry 102 for branch BrY does notdepend on any contents of the first victim entry 100 since the secondvictim entry 102 will always have the same set index as the first victimentry. This means that, for example, if the victim selection of thesecond victim entry 102 depends on replacement policy information (e.g.round robin information tracking the least recently allocated entry inthe set, or least recently used (LRU) information tracking the leastrecently looked up entry in the set), the replacement policy informationcan be read before any reads of the first victim entry 100 are complete,which can reduce the latency of performing the migration of entry 100 tothe L2 BTB 70. In contrast, in FIG. 4 in case 1, the set index for entryBrY to be evicted from the L2 BTB 70 cannot be determined until afterthe tag has been read from the victim entry for branch BrX selected inthe L1 BTB 68, which could map to a different set in the L2 BTB 70compared to the set associated with the looked up address for branchBrA.

Hence, in case 1 the approach shown in FIG. 5 can provide opportunitiesfor performance improvement by allowing increased parallelizationbetween the operations for looking up the first level BTB and operationsfor selecting the second victim entry 102 (e.g. reading of replacementpolicy information associated with entries in the selected set of thesecond level BTB 70 could start before tags of the first level BTB havebeen read out for the selected set in the first level BTB 68).

Similarly, in case 2 explained with respect to FIG. 4, when the approachshown in FIG. 5 is used then, rather than needing a third entry to beupdated for branch Br2 as shown in FIG. 4, instead in FIG. 5 thecontents of a first victim entry 104 and a second victim entry 106 inthe L1 and L2 BTBs 68, 70 respectively can simply be swapped. Byavoiding the need for a third entry to be updated this improvesperformance when swapping entries between the levels of cache. Also,this can help to improve cache hit rates because the swapping of entries104 and 106 means there is no need to evict information for a furtherbranch Br2 from the L2 BTB, helping to improve performance. Again, thisapproach allows the victim selection operations for selecting the secondvictim entry 106 to start before a tag value of the first victim entry104 has been read, for example.

Portions of the victim selection operation for selecting the secondvictim entry 102, 106 in either case 1 or case 2 may be performed inparallel with at least one of: a portion of a first-level cache lookupto identify whether there is a cache hit or miss in the L1 BTB 68, at aportion of second-level cache lookup to determine whether there is acache hit or miss in the second-level BTB 70, or an operation to readcontents 56, 58 of a victim entry 100, 104 in the first-level BTB 68.

The techniques shown in FIG. 5 can be particularly useful forimplementations using single-ported cache RAM. As shown in FIG. 6, adual ported cache RAM 190 could be used to implement one of the caches68, 70, and in this case the cache may include a first read/write port192 and a second read/write port 194, which in each processing cycle caneach provide a read or write request to the cache RAM 190, Hence, it ispossible to perform both a read and a write to the cache in the samecycle (to different locations within the cache). In contrast, FIG. 7shows a single-ported cache RAM 196 which only has a single read/writeport 198 and so is only capable of either a read or a write in any givencycle. When performing migrations of entries between levels of cachethen this may require some entries to be both read and written, which ina single-ported cache RAM 196 as shown in FIG. 7 would not be possiblein the same cycle. Hence, any techniques which can be used to reduce thenumber of entries which need to be updated or to allow greaterparallelism of operations between the first and second levels of cache(which could each be implemented as a separate module of single-portedcache RAM so that it is possible to perform a read/write the secondlevel cache 70 in parallel with a read/write to the first-level cache68) may greatly help to reduce the timing pressure, which isparticularly useful for BTB structures because the branch predictor 40is a busy component being looked up in virtually every cycle, unlikeother less frequently accessed cache structures such as the L1 datacache 30.

Nevertheless, the techniques shown in FIG. 5 of providing the samenumber of sets in both L1 and L2 caches could also be used for othertypes of prediction cache, or for caches which do not provide anyprediction at all (such as the L1 and L2 data caches 30, 32). While theexamples above show a hierarchy with only two cache levels, it ispossible to apply the technique to any two levels among a hierarchy withthree or more levels. If there is a third cache level then it is notessential for that third cache level to include the same number of setsas the other two levels, or alternatively the third level may also haveits number of sets aligned with the other two levels so as to provide acommon indexing scheme for the third level as well. Hence, in generalwhile there may be at least two levels which share the same set indexingscheme provided by the indexing circuitry 66, it is not essential forall levels of cache to implement this. A performance improvement may beprovided even if the number of sets is the same only for a subset of atleast two caches among a hierarchy including three or more levels ofcache.

FIG. 8 illustrates a method of controlling cache accesses. At step S200information is cached in a L1 cache 68. At step S202 information iscached in a L2 cache 70 having the same number of sets 50 as the L1cache 68, where both the L1 and L2 caches are set-associative caches. Atstep S204, indexing circuitry 66 generates, based on a lookup address 80to be looked up in one or both of the levels of cache 68, 70, a setindex 84 identifying which set 50 of entries 52 in the L1 and/or L2caches 68, 70 is the selected set to be looked up to check whether anyof the entries in the selected set contains information for the lookupaddress. The set indexing scheme used by the indexing circuitry 66 isthe same for both first and second levels of cache 68, 70, so that thelookup addresses map to the same set index 84 for both levels. At stepS206 the cache access circuitry 72 controls access to the respectivelevels of cache using the set index 84 generated at step S204.

FIG. 9 shows a flow diagram illustrating in more detail control oflookups to the first and second level caches 68, 70. At step S250, theindexing circuitry 66 generates, based on the lookup address 80, the setindex 84 identifying the selected set of entries in both the L1 and L2caches 68, 70 (the same set index is generated for both levels). A hashfunction could be used to map the lookup address to the set index. Thehash function could take as inputs the lookup address, and optionally atleast one other parameter such as branch history information 82 asdiscussed above.

At step S252 a first cache lookup is performed by the cache accesscircuitry 72 to determine whether any of the selected set of L1 cacheentries identified by the set index 84 provide valid data correspondingto the lookup address. The first cache lookup compares the tags 56 inthe selected set 50 of entries identified by the set index 84 with a tagportion 85 derived from the lookup address 80. At step S254 the cacheaccess circuitry 72 determines whether the L1 cache lookup identified ahit or a miss (a hit occurs when one of the selected set of entries hasa tag 56 corresponding to the tag portion 85 for the lookup address, anda miss occurs when none of the selected set of entries has a tag 56corresponding to the tag portion 85), If a hit is detected, then at stepS256 cached information is returned from the hit entry of the selectedset of entries in the L1 cache; where the hit entry is the entry forwhich the tag 56 match the tag as derived from the lookup address 80. Ifa hit is detected, it is not essential to look up the L2 cache 70,although in implementations where it is possible that the L2 cache couldcache further information associated with the lookup address (e.g.additional branch information relating to other branches in the sameinstruction block), then the method could continue to step S258 forperforming a second cache lookup.

If at step S254 a miss was detected in the L1 cache then at step S258 asecond cache lookup is performed, using the set index derived at stepS250, to determine whether any of the selected set of cache entries inthe L2 cache 70 corresponds to the lookup address. As shown in thedotted line in FIG. 9, optionally the second cache lookup at step S258could be initiated in parallel with the first cache lookup at step S252,regardless of whether the first cache lookup generates a hit or a miss.However, in some cases the second cache lookup may be activatedsubsequent to the first cache lookup once it has been determined whethera hit has been detected in the first cache lookup, to avoid incurringthe power cost associated with performing the second cache lookup if thesecond cache lookup is not necessary.

At step 3260, the cache access circuitry compares the tags 86 in theselected set 50 of L2 cache entries corresponding to the set index 84with the tag portion 85, and determines whether there is a hit entrycorresponding to the lookup address 80. If a hit is detected in the L2cache 70 then at step S261 the cache access circuitry 72 returns thecached information from the hit entry of the L2 cache for use by theprediction circuitry 74 or other circuit element which is requestingthis information. At step S262 the cache access circuitry 72 determineswhether there is an invalid L1 cache entry available in the selected setof the L1 cache 68 corresponding to the set index 84, and if so then atstep S263 the information from the hit entry of the L2 cache 70 can beallocated to that invalid entry of the L1 cache 68 and the hit entry canbe invalidated in the L2 cache 70. However, if there is no invalid entryavailable in the selected set of the L1 cache, then at step S264 thecache access circuitry 72 controls the L1 and L2 caches 68, 70 to swapthe contents of the hit entry 106 in the L2 cache with a victim entry104 of the L1 cache. The selection of the victim entry in thefirst-level cache 68 may depend on replacement policy informationassociated with the set of entries 50 in the first-level cache 68 whichcorresponds to the set index 84. As shown at step S268, operations toread the replacement policy information for victim selection in the L1cache 68 can be initiated once the set index has been derived from thelookup address at step S250 and they take place in parallel with otheroperations performed in the first cache lookup or second cache lookup.The reading of the replacement policy information for victim selectionin the first level cache does not depend on the contents of the hitentry in the L2 cache identified at step S260, and so can be performedin parallel and this may accelerate the selection of the victim entry towhich the contents of the hit entry of the L2 cache are to be written inthe L1 cache 68. Also, there is no need to evict a further L2 BTB entry(similar to the entry for Br2 in FIG. 4), as branches Br0 and BrA in thefirst victim entry 104 and hit entry 106 always correspond to the sameset index in both levels of cache 68, 70.

On the other hand if at step S260 the L2 cache lookup performed at stepS258 identifies a cache miss, at step S265 the cache access circuitry 72determines whether there is an invalid entry available in the L1 cache68 in the selected set corresponding to the set index 84. If so, at stepS266 information associated with the lookup address is allocated to thatinvalid entry. This newly allocated information may not be allocatedright away e.g. for a data cache hierarchy this information may need towait for a cache linefill from memory, or for a BTB cache hierarchy asshown in FIG. 2 the allocation may need to wait for actual branchinformation to be determined at the branch unit 24 in the execute stageof the pipeline. If there is no invalid entry available in the selectedset of the L1 cache 68, then eviction of some information from a firstvictim entry 100 of the L1 cache is performed. In that case, at stepS267 contents of a first victim entry 100 in the L1 cache 68 are writtento a second victim entry 102 in the L2 cache 70 and the first victimentry 100 is allocated for storing the new information associated withthe lookup address 80 which was not previously cached in either the L1or L2 caches 68, 70. Information from the second victim entry 102 in theL2 cache 70 is discarded. Again, selection of both the first and secondvictim entries 100, 102 may depend on replacement policy informationwhich can be read at step S268 in parallel with other aspects of thefirst and second cache lookups. In particular, the replacement policyinformation for selecting the second victim entry 102 can be read atstep S268 without waiting for a tag of the first victim entry 100 to beread, because the selection of the second victim entry is independent ofcontents of the first victim entry 100. This is due to the use of thesame set indexing schemes in both L1 and L2 caches 68, 70. This canprovide more opportunities for pipelining of operations to improveperformance.

In the present application, the words “configured to . . . ” are used tomean that an element of an apparatus has a configuration able to carryout the defined operation. In this context, a “configuration” means anarrangement or manner of interconnection of hardware or software. Forexample, the apparatus may have dedicated hardware which provides thedefined operation, or a processor or other processing device may beprogrammed to perform the function. “Configured to” does not imply thatthe apparatus element needs to be changed in any way in order to providethe defined operation.

Although illustrative embodiments of the invention have been describedin detail herein with reference to the accompanying drawings, it is tobe understood that the invention is not limited to those preciseembodiments, and that various changes and modifications can be effectedtherein by one skilled in the art without departing from the scope ofthe invention as defined by the appended claims.

1. An apparatus comprising: a first-level set-associative cachecomprising a plurality of sets of cache entries; a second-levelset-associative cache comprising a plurality of sets of cache entries,where a number of sets in the first-level set-associative cache is thesame as a number of sets in the second-level set-associative cache; andindexing circuitry to generate, based on a lookup address, a set indexidentifying which set of the first-level set-associative cache or thesecond-level set-associative cache is a selected set of cache entries tobe looked up for information associated with the lookup address, wherethe indexing circuitry is configured to generate the set index using anindexing scheme which maps the lookup address to the same set index forboth the first-level set-associative cache and the second-levelset-associative cache.
 2. The apparatus according to claim 1, comprisingcache access circuitry to perform: a first cache lookup to determinewhether any of the selected set of cache entries in the first-levelset-associative cache caches the information associated with the lookupaddress; and a second cache lookup to determine whether any of theselected set of cache entries in the second-level set-associative cachecaches the information associated with the lookup address.
 3. Theapparatus according to claim 2, in which when the second cache lookupidentifies a cache hit where a hit entry of the selected set of cacheentries in the second-level set-associative cache caches the informationassociated with the lookup address, and there is no invalid entry in theselected set of cache entries in the first-level set-associative cachewhich can accommodate the information from the hit entry, the cacheaccess circuitry is configured to swap contents of the hit entry of thesecond-level set-associative cache and a victim entry of the selectedset of cache entries in the first-level set-associative cache.
 4. Theapparatus according to claim 3, in which when the second cache lookupidentifies the cache hit and there is no invalid entry in the selectedset of cache entries in the first-level set-associative cache which canaccommodate the information from the hit entry, the cache entry of thesecond-level set-associative cache that is updated with contents of thevictim entry of the first-level set-associative cache is the hit entryregardless of which address is associated with information cached in thevictim entry of the first-level set-associative cache.
 5. The apparatusaccording to claim 3, in which, when swapping the contents of the hitentry of the second-level set-associative cache and the victim entry ofthe first-level set-associative cache, the cache access circuitry isconfigured to perform an atomic update operation on the hit entry andthe victim entry.
 6. The apparatus according to claim 2, in which whenboth the first cache lookup and the second cache lookup identify a cachemiss where none of the selected set of cache entries in the first-levelset-associative cache and the second-level set-associative cache cachesthe information associated with the lookup address, the cache accesscircuitry is configured to write contents of a first victim entry of theselected set of cache entries in the first-level set-associative cacheto a second victim entry of the selected set of cache entries of thesecond-level set-associative cache and allocate the first victim entryfor storing information associated with the lookup address.
 7. Theapparatus according to claim 6, in which the cache access circuitry isconfigured to select the second victim entry independent of the contentsof the first victim entry.
 8. The apparatus according to claim 6, inwhich the cache access circuitry is configured to select the secondvictim entry based on replacement policy information associated with theselected set of cache entries of the second-level set-associative cache,and is configured to read the replacement policy information before aread of the first victim entry is complete.
 9. The apparatus accordingto claim 6, in which the cache access circuitry is configured to selectthe second victim entry based on replacement policy informationassociated with the selected set of cache entries of the second-levelset-associative cache, and is configured to read the replacement policyinformation in parallel with at least one of: the first cache lookup;the second cache lookup; and reading of the first victim entry to obtainthe contents to be written to the second victim entry.
 10. The apparatusaccording to claim 6, in which the cache access circuitry is configuredto perform an atomic update operation on the first victim entry and thesecond victim entry to allocate the first victim entry for storing theinformation associated with the lookup address and to write the contentsof the first victim entry to the second victim entry.
 11. The apparatusaccording to claim 1, in which, in response to a cache access request torequest information associated with the lookup address, when theinformation associated with the lookup address is obtained from thefirst-level set-associative cache, the information is accessible infewer cycles than when the information associated with the lookupaddress is obtained from the second-level set-associative cache.
 12. Theapparatus according to claim 1, in which the second-levelset-associative cache is an exclusive cache.
 13. The apparatus accordingto claim 1, in which the second-level set-associative cache has agreater number of ways per set than the first-level set-associativecache.
 14. The apparatus according to claim 1, in which the first-levelset-associative cache and the second-level set-associative cache eachcomprise single-ported random access memory.
 15. The apparatus accordingto claim 1, comprising prediction circuitry to determine a predictedbehaviour associated with the lookup address based on information cachedin a cache entry of the first-level set-associative cache or thesecond-level set-associative cache associated with the lookup address.16. The apparatus according to claim 1, comprising branch predictioncircuitry to determine a predicted branch instruction behaviourassociated with the lookup address based on branch predictioninformation cached in a cache entry of the first-level set-associativecache or the second-level set-associative cache associated with thelookup address.
 17. The apparatus according to claim 1, comprisingbranch prediction circuitry to determine a predicted target address fora first taken branch instruction predicted to occur within a block ofone or more instructions associated with the lookup address, based onbranch target buffer information cached in a cache entry of thefirst-level set-associative cache or the second-level set-associativecache associated with the lookup address.
 18. An apparatus comprising:first-level means for caching information in a plurality of sets ofcache entries accessed according to a set-associative cache accesspolicy; second-level means for caching information in a plurality ofsets of cache entries accessed according to a set-associative cacheaccess policy, where a number of sets in the first-level means forcaching is the same as a number of sets in the second-level means forcaching; and means for generating, based on a lookup address, a setindex identifying which set of the first-level means for caching or thesecond-level means for caching is a selected set of cache entries to belooked up for information associated with the lookup address; where themeans for generating is configured to generate the set index using anindexing scheme which maps the lookup address to the same set index forboth the first-level means for caching and the second-level means forcaching.
 19. A method comprising: caching information in a first-levelset-associative cache comprising a plurality of sets of cache entries;caching information in a second-level set-associative cache comprising aplurality of sets of cache entries, where a number of sets in thefirst-level set-associative cache is the same as a number of sets in thesecond-level set-associative cache; and generating, based on a lookupaddress, a set index identifying which set of the first-levelset-associative cache or the second-level set-associative cache is aselected set of cache entries to be looked up for information associatedwith the lookup address, where the set index is generated using anindexing scheme which maps the lookup address to the same set index forboth the first-level set-associative cache and the second-levelset-associative cache.